
# -*- encoding:utf-8 -*-

import threading
import time
import datetime
from utils.SafeList import SafeList

__author__ = 'shudong.msd'

# 超时检测，本程序不用也无妨。
class TimeScan(threading.Thread):

    __sleep_interval = 1
    __time_out = 60
    __q_running = SafeList()

    def __init__(self,timeout=60,q_running=SafeList()):
        threading.Thread.__init__(self)
        self.__time_out = timeout
        self.__q_running = q_running

    def run(self):

        while True:
            for row in self.__q_running:
                timespan = datetime.datetime.now().second - row['starttime']
                if timespan > self.__time_out:
                    # 丢弃超时任务，后期也可以添加重试。这里没太大必要
                    self.__q_running.remove(row)
                    print '超时了'
            time.sleep(self.__sleep_interval)




